package com.example.hospitalmanagement.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.bean.ChargeData
import com.example.hospitalmanagement.bean.DrugPriceData

/**
 * 收费项目条目所使用的适配器
 */
class DrugPriceActivityAdapter(context: Context) :
    RecyclerView.Adapter<DrugPriceActivityAdapter.PriceHolder>() {
    private val context = context
    lateinit var dataList: MutableList<DrugPriceData>
    class PriceHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val itemIcon: ImageView = itemView.findViewById(R.id.drug_price_items_icon)
        val itemName: TextView = itemView.findViewById(R.id.drug_price_items_name)
        val itemText: TextView = itemView.findViewById(R.id.place_of_origin)
        val itemPrice: TextView = itemView.findViewById(R.id.drug_price_items_price)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PriceHolder {
        return PriceHolder(
            LayoutInflater.from(context).inflate(R.layout.drug_price_items, parent, false)
        )
    }

    override fun onBindViewHolder(holder: PriceHolder, position: Int) {
        if (dataList[position].checked) {
            holder.itemIcon.isVisible = true
        } else {
            holder.itemIcon.isGone = true
        }

        holder.itemName.text = dataList[position].productName
        holder.itemText.text = "产地:${dataList[position].placeName}"
        holder.itemPrice.text = "价格:${dataList[position].salePrice}元/支"

    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}